using UnityEngine;
using System.Collections;

public class CatSpawner : MonoBehaviour 
{
	public Vector3[] positions;
	public GameObject cat;
	
	float timer;
	float limit = 3.0f;
	
	int random;
	
	public GameObject fadeOut;
	GameObject go;
	
	void Start () 
	{
		
	}
	
	void Update () 
	{
		timer += Time.deltaTime;
		go = GameObject.Find("Main Camera");
		
		if(timer >= limit)
		{
			Spawn();
			timer = 0;
			limit -= 0.1f;
		}
		
		if(limit <= -0.5f)
		{
			fadeOut.gameObject.SetActive(true);
			go.GetComponent<Wait>().StartWaiting(4);
		}
		
		if(!go.GetComponent<Wait>().isWaiting)
		{
			Application.LoadLevel("Dialog_02");
		}
	}
	
	public void Spawn()
	{
		random = Random.Range(0, 12);
		
		if(random > 3 && random <= 7)
		{
			cat.transform.localScale = new Vector3(1.5f, 1.5f, gameObject.transform.localScale.z);
		}
		else if(random > 7 && random <= 12)
		{
			cat.transform.localScale = new Vector3(2, 2, gameObject.transform.localScale.z);
		}
		else
		{
			cat.transform.localScale = new Vector3(gameObject.transform.localScale.x, gameObject.transform.localScale.y, gameObject.transform.localScale.z);
		}
		
		Instantiate(cat, positions[random], cat.transform.rotation);
	}
}
